package cs2340.droidceptiontodo.test;

import java.util.ArrayList;
import java.util.List;
import cs2340.droidceptiontodo.Database;
import cs2340.droidceptiontodo.ToDoItem;
import cs2340.droidceptiontodo.UserAccount;
import android.test.AndroidTestCase;
import android.test.RenamingDelegatingContext;
import android.util.Log;


public class GetItemsTest extends AndroidTestCase {
		private Database database;
		private List<ToDoItem> items;
		private static final String TEST_FILE_PREFIX = "test_";

		protected void setUp() throws Exception {
			super.setUp();
			
			RenamingDelegatingContext context = new RenamingDelegatingContext(getContext(), TEST_FILE_PREFIX);
			database = new Database(context);
			items = new ArrayList<ToDoItem>();
			
			 	items.add(new ToDoItem("0", "user", "details", "Work", "2015/04/05", "12:05", "location", true, null));
				items.add(new ToDoItem("1", "user", "details", "Work", "2014/04/05", "12:05", "location", false, null));
				items.add(new ToDoItem("2", "user", "details", "School", "2012/01/05", "12:05", "location", true, null));
				items.add(new ToDoItem("3", "user", "details", "School", "2012/12/05", "12:05", "location", false, null));
				items.add(new ToDoItem("4", "user", "details", "Personal", "2012/12/01", "12:05", "location", false, null));
				items.add(new ToDoItem("5", "user", "details", "Personal", "2011/04/05", "12:05", "location", true, null));
				database.open();
				for(ToDoItem item:items) {
					database.addItem(item);
				}
		}
		
		public void testPreConditions() {
		    assertNotNull(database);
		}

		public void testSetSetting() {
			assertEquals(database.checkUser("erin", "sam"), -1);
			assertEquals(database.checkUser(null, null), -1);
			List<ToDoItem> actual = database.getItems("user");
			assertEquals(actual.size(), items.size());
			for(int i=0; i<items.size(); i++) {
				assertEquals(items.get(i).getName(), actual.get(i).getName());
			}
			List<ToDoItem> empty = new ArrayList<ToDoItem>();
			List<ToDoItem> listofImaginaryUser = database.getItems("bob");
			Log.d("Debug", "empty list is size" + empty.size());
			assertEquals(empty.size(), listofImaginaryUser.size());
		}
		
		@Override
		protected void tearDown() throws Exception {
		    super.tearDown();

		    database.close();
		    database = null;
		}
		
}
